using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml;
using SplitXMLIntoFiles.Properties;

namespace SplitXMLIntoFiles
{
    public partial class Main : Form
    {
        private const int MB = 1000000;
        public Main()
        {
            InitializeComponent();
        }

        private string ImportXMLDoc()
        {
            openFileDlg = new OpenFileDialog { Filter = "XML files|*.xml|All files|*.*" };
            openFileDlg.ShowDialog();
            return openFileDlg.FileName;
        }

        private void BtnSplitClick(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtFileSize.Text))
            {
                MessageBox.Show(Resources.Main_btnSplit_Click_Enter_split_value_in_MB);
                return;
            }

            var fileName = ImportXMLDoc();
            var size = Double.Parse(txtFileSize.Text.Trim()) * MB;
            var fileProcessor = new FileProcessor();
            var numOfNewFiles = fileProcessor.SplitFile(size, fileName);

            MessageBox.Show(Resources.Main_btnSplit_Click_Done__ + numOfNewFiles + Resources.Main_btnSplit_Click_ + Application.StartupPath);
        }
    }
}